﻿var vm = new Vue({
    el: '#app'
    , data: {
        menus: []
        , activeTabsName: 'home'
        , tabs: [{
            title: '首页'
            , name: 'home'
            , closable: false
            , url: hcCore.virtualDirectory + '/show/Index'
        }]
        , url: hcCore.virtualDirectory + '/theme/default/images/logo.png'
    }
    , mounted: function () {
        this.getMenus();
    }
    , methods: {
        addTab: function (name, title, url) {
            let tab = this.tabs.filter(function (p) { return p.name == name });
            if (tab && tab.length > 0) { }
            else {
                this.tabs.push({
                    title: title,
                    name: name,
                    url: url,
                    closable: true
                });
            }
            this.activeTabsName = name;
        },
        removeTab: function (targetName) {
            let tabs = this.tabs;
            let activeName = this.activeTabsName;
            if (activeName === targetName) {
                tabs.forEach(function (tab, index) {
                    if (tab.name === targetName) {
                        let nextTab = tabs[index + 1] || tabs[index - 1];
                        if (nextTab) {
                            activeName = nextTab.name;
                        }
                    }
                });
            }

            this.activeTabsName = activeName;
            this.tabs = tabs.filter(function (tab) { return tab.name !== targetName });
        }
        , getMenus: function () {
            let me = this;
            hcCore.post({
                url: '/Home/Menus'
                , success: function (rsp) {
                    me.menus = rsp.data;
                }
            });
        }
    }
});